package com.stxx.stiot2.controller;

import com.stxx.framwork.domain.R;
import com.stxx.framwork.domain.model.PageQuery;
import com.stxx.framwork.domain.model.PageResult;
import com.stxx.stiot2.domain.Profile;
import com.stxx.stiot2.service.ProfileService;
import org.noear.solon.annotation.*;

import java.sql.SQLException;

@Controller
@Mapping("/profile")
public class ProfileController {

    @Inject
    ProfileService baseService;

    @Get
    @Mapping("/list")
    public PageResult<Profile> list(Profile bo, PageQuery pageQuery) throws SQLException {
        PageResult<Profile> r = baseService.pageList(bo,pageQuery);
        return r;
    }

    @Get
    @Mapping("/info/{id}")
    public R<Profile> info(@Path String id) throws SQLException {
       Profile r = baseService.queryById(id);
        return R.ok(r);
    }



    @Post
    @Mapping("")
    public R<Object> add(@Body Profile bo) throws SQLException {
        baseService.insert(bo);
        return R.ok("数据保存成功");
    }

    @Put
    @Mapping("")
    public R<Object> edit(@Body Profile bo) throws SQLException {
        baseService.update(bo);
        return R.ok("数据保存成功");
    }

    @Delete
    @Mapping("/{ids}")
    public R<Object> remove(@Path String[] ids) throws SQLException {
        baseService.deleteByIds(ids);
        return R.ok("数据删除成功");
    }
}
